/* **********************************************************************************
*
* Copyright (c) Microsoft Corporation. All rights reserved.
*
* This source code is subject to terms and conditions of the Shared Source License
* for DSL Editor PowerToy. A copy of the license can be found in the License.htm file
* at the root of this distribution. If you can not locate the Shared Source License
* for DSL Editor PowerToy, please obtain a copy from: http://www.codeplex.com/dsltreegrideditor/Project/License.aspx.
* By using this source code in any fashion, you are agreeing to be bound by
* the terms of the Shared Source License for DSL Editor PowerToy.
*
* You must not remove this notice, or any other, from this software.
*
* **********************************************************************************/
using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.IO;
using System.Text;

using EnvDTE;

using Microsoft.VisualStudio.Modeling.Validation;

namespace DslEditorPowerToy.Languages.EditorConfiguration
{
    #region Validation
    [ValidationState(ValidationState.Enabled)]
    partial class DslDomain
    {
        #region Validation Methods
        [ValidationMethod(ValidationCategories.Save | ValidationCategories.Menu | ValidationCategories.Open)]
        internal void ValidateViewsExist(ValidationContext context)
        {
            //Verify at least one view is defined
            if (0 == this.DslEditors.Count)
                context.LogError(Resources.DomainNoEditorsExist, Resources.Class_DomainNoEditorsExist, this);
        }
        [ValidationMethod(ValidationCategories.Save | ValidationCategories.Menu | ValidationCategories.Open)]
        internal void ValidateViewsActive(ValidationContext context)
        {
            //Verify at least one view is active
            if (this.DslEditors.Count > 0)
            {
                int activeCount = 0;
                foreach (DslEditor view in this.DslEditors)
                {
                    if (true == view.Active)
                        activeCount++;
                }
                if (0 == activeCount)
                    context.LogWarning(Resources.DomainNoEditorsActive, Resources.Class_DomainNoEditorsActive, this);
            }
        }
        [ValidationMethod(ValidationCategories.Save | ValidationCategories.Menu | ValidationCategories.Open)]
        internal void ValidateToolWindowTitle(ValidationContext context)
        {
            //Only valid for toolwindow hosting
            if (EditorHostStyle.ToolWindow == this.HostingStyle)
            {
                //Verify caption is specified
                if (true == string.IsNullOrEmpty(this.ToolWindowTitle))
                    context.LogError(Resources.DomainToolWindowTitleUndefined, Resources.Class_DomainToolWindowTitleUndefined, this);
            }
        }
        [ValidationMethod(ValidationCategories.Save | ValidationCategories.Menu | ValidationCategories.Open)]
        internal void ValidateToolWindowBitmaps(ValidationContext context)
        {
            //Only valid for toolwindow hosting
            if (EditorHostStyle.ToolWindow == this.HostingStyle)
            {
                //Verify bitmap file is specified
                if (true == string.IsNullOrEmpty(this.ToolWindowBitmapsFile))
                {
                    context.LogError(Resources.DomainToolWindowBitmapsUndefined,
                        Resources.Class_DomainToolWindowBitmapsUndefined, this);
                    return;
                }

                //Verify bitmap file exists
                if (false == File.Exists(this.ToolWindowBitmapsFile))
                    context.LogError(Resources.DomainToolWindowBitmapsNotExist,
                        Resources.Class_DomainToolWindowBitmapsNotExist, this);
            }
        }
        #endregion
    }
    #endregion

    #region Property Display
    [TypeDescriptionProvider(typeof(EditorConfigurationDescriptionProvider))]
    partial class DslDomain
    {
    }
    #endregion
}
